﻿
Imports System.IO
Imports osi.root.envs
Imports osi.root.connector
Imports osi.root.constants

Namespace error_handle
    Public Class file_error_writer
        Inherits application_info_writer
        Implements ierror_writer

        Public Shared ReadOnly instance As locked_writer(Of error_type_selected_error_writer) = Nothing

        Shared Sub New()
            instance = create()
        End Sub

        Public Shared Function create(Optional ByVal logfile As String = Nothing) _
                                     As locked_writer(Of error_type_selected_error_writer)
            Return New locked_writer(Of error_type_selected_error_writer) _
                                    (New error_type_selected_error_writer(New file_error_writer(logfile)))
        End Function

        Private Sub New(Optional ByVal logfile As String = Nothing)
            MyBase.New(log_folder, logfile, "log")
        End Sub

        Public Function [select](ByVal error_type As error_type,
                                 ByVal error_type_char As Char) As Boolean Implements ierror_writer.select
            Return True
        End Function

        Public Sub write(ByVal errtype As error_type, ByVal s As String) Implements ierror_writer.write
            Try
                writer().WriteLine(s)
            Catch ex As Exception
                k_raise_error("write log content ", s, " failed, ex ", ex.Message())
            End Try
        End Sub
    End Class
End Namespace
